package com.binhthuan.catechist.client.data;

import com.binhthuan.catechist.shared.constant.Parameter;
import com.binhthuan.catechist.shared.constant.Service;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.widgets.form.fields.SelectItem;

public class TrainerDS extends PersonDS {

    private static TrainerDS instance;

    private TrainerDS() {
        super(Service.TRAINER);

        DataSourceTextField comment = new DataSourceTextField(Parameter.COMMENT);

        /*SelectItem doctrineClassEditor = new SelectItem(Parameter.CURRENT_COURSE);
        doctrineClassEditor.setRequired(true);
        doctrineClassEditor.setValueField(Parameter.ID);
        doctrineClassEditor.setDisplayField(Parameter.NAME);
        doctrineClassEditor.setOptionDataSource(CourseDS.getInstance());
        doctrineClassEditor.setWidth(250);
        doctrineClassEditor.setDefaultToFirstOption(true);

        DataSourceTextField currentDoctrineClass = new DataSourceTextField(Parameter.CURRENT_COURSE);
        currentDoctrineClass.setValueXPath(combineXPath(Parameter.CURRENT_COURSE, Parameter.ID));
        currentDoctrineClass.setTypeAsDataSource(CourseDS.getInstance());
        currentDoctrineClass.setEditorType(doctrineClassEditor);
*/
        DataSourceTextField email = new DataSourceTextField(Parameter.EMAIL);

        DataSourceDateField feastDay = new DataSourceDateField(Parameter.FEAST_DAY);

        DataSourceDateField joinDate = new DataSourceDateField(Parameter.JOIN_DATE);

        SelectItem statusEditor = new SelectItem(Parameter.STATUS);
        statusEditor.setRequired(true);
        statusEditor.setValueField(Parameter.ID);
        statusEditor.setDisplayField(Parameter.NAME);
        statusEditor.setOptionDataSource(TrainerStatusDS.getInstance());
        statusEditor.setDefaultToFirstOption(true);

        DataSourceTextField status = new DataSourceTextField(Parameter.STATUS);
        status.setValueXPath(combineXPath(Parameter.STATUS, Parameter.ID));
        status.setTypeAsDataSource(TrainerStatusDS.getInstance());
        status.setEditorType(statusEditor);

        DataSourceTextField statusName = new DataSourceTextField(Parameter.STATUS_NAME);
        statusName.setValueXPath(combineXPath(Parameter.STATUS, Parameter.NAME));

        addField(comment);
        //addField(currentDoctrineClass);
        addField(email);
        addField(feastDay);
        addField(joinDate);
        addField(status);
        addField(statusName);
    }

    @Override
    public int getType() {
        return Parameter.PersonType.TRAINER_TYPE;
    }

    public static TrainerDS getInstance() {
        if (instance == null) {
            instance = new TrainerDS();
        }
        return instance;
    }
}
